package com.bootlever.framework.fastdfs.configuration;

import com.bootlever.framework.fastdfs.properties.FastdfsProperties;
import com.bootlever.framework.fastdfs.templates.FastdfsTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
@ConditionalOnExpression("'${bootlever.framework.fastdfs.enable:true}'=='true'")
public class FastdfsConfiguration {

    @Autowired
    private FastdfsProperties fastdfsProperties;

    @Bean
    @ConditionalOnMissingBean(FastdfsTemplate.class)
    public FastdfsTemplate fastdfsTemplate() throws IOException {
        FastdfsTemplate fastdfsTemplate = new FastdfsTemplate(fastdfsProperties);
        return fastdfsTemplate;
    }
}
